package com.action.user;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.business.user.UserInfoBus;
import com.config.SystemGlobals;
import com.util.MD5;

public class AdminLogin extends HttpServlet {

	private static final long serialVersionUID = 1L;
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		 String contentType = SystemGlobals.getValue("contentType");
			PrintWriter out = response.getWriter();
			response.setContentType(contentType);
			String userName = request.getParameter("username");
			String passwordF= request.getParameter("password");
			String code = request.getParameter("authencode");
			HttpSession session = request.getSession();
			String password = new MD5().getMD5ofStr(passwordF);
			UserInfoBus uib = new UserInfoBus();
			if (!uib.checkAdminLogin(userName, password).equals("")) {
				String AuthenCode = (String) request.getSession().getAttribute(
						"AuthenCode");
				if (!code.equals(AuthenCode)) {
					out
							.print("<script>alert(\"验证码有误\");history.back(-1);</script>"); 
				}else {
					
					session.setAttribute("login_admin", userName);
					session.setAttribute("GroupNo",uib.checkAdminLogin(userName, password));
					
					response.sendRedirect(
                    "admin/index.jsp");
				
				}
			}

			else {
				out
						.println("<script>alert(\"您的输入信息不正确,请重新输入\");history.back(-1);</script>");
				out.close();
			}
		}

	}

